package org.dromara.demo.controller;

import io.appium.java_client.android.AndroidDriver;
import lombok.extern.slf4j.Slf4j;
import org.openqa.selenium.By;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.springframework.boot.test.context.SpringBootTest;

import java.net.MalformedURLException;
import java.net.URL;


@Slf4j
@SpringBootTest
public class SampleTest {

    public static void main(String[] args) throws MalformedURLException {
        DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
        desiredCapabilities.setCapability("platformName", "Android");
        desiredCapabilities.setCapability("deviceName", "xiaomi");
        desiredCapabilities.setCapability("appium:platformVersion", "12.0.6");
        desiredCapabilities.setCapability("appPackage", "com.hitachi.yunjia");
        desiredCapabilities.setCapability("appActivity", "cn.com.hitachi.StartActivity");
        desiredCapabilities.setCapability("noReset", true);
        desiredCapabilities.setCapability("appium:ensureWebviewsHavePages", true);
        desiredCapabilities.setCapability("appium:nativeWebScreenshot", true);
        desiredCapabilities.setCapability("appium:connectHardwareKeyboard", true);
        URL remoteUrl = new URL("http://127.0.0.1:4723/wd/hub");
        AndroidDriver androidDriver = new AndroidDriver(remoteUrl, desiredCapabilities);
        WebDriverWait wait = new WebDriverWait(androidDriver, 10);
        wait.until(ExpectedConditions.presenceOfElementLocated(By.id("com.hitachi.yunjia:id/iv_switch")));
        androidDriver.findElement(By.id("com.hitachi.yunjia:id/iv_switch")).click();
    }
}
